package com.zany.children.service;

import com.zany.children.dao.ChargesOwedDao;
import com.zany.children.dao.ChargesOwedDetailDao;
import com.zany.children.vo.ChargesOwed;
import com.zany.children.vo.ChargesOwedDetail;
import com.zany.children.vo.PaymentProject;
import com.zany.system.vo.UserInfoVO;

import java.util.List;
import java.util.Map;

public class ChargesOwedDetailServiceImpl implements ChargesOwedDetailService {

    public ChargesOwedDetailDao getChargesOwedDetailDao() {
        return chargesOwedDetailDao;
    }

    public void setChargesOwedDetailDao(ChargesOwedDetailDao chargesOwedDetailDao) {
        this.chargesOwedDetailDao = chargesOwedDetailDao;
    }

    private ChargesOwedDetailDao chargesOwedDetailDao;

    public ChargesOwedDao getChargesOwedDao() {
        return chargesOwedDao;
    }

    public void setChargesOwedDao(ChargesOwedDao chargesOwedDao) {
        this.chargesOwedDao = chargesOwedDao;
    }

    private ChargesOwedDao chargesOwedDao;

    @Override
    public Long saveChargesOwedDetail(ChargesOwedDetail chargesOwedDetail) {
        return chargesOwedDetailDao.saveChargesOwedDetail(chargesOwedDetail);
    }


    @Override
    public void updateChargesOwedDetail(ChargesOwedDetail chargesOwedDetail) {
        chargesOwedDetailDao.updateChargesOwedDetail(chargesOwedDetail);
    }

    @Override
    public void deleteChargesOwedDetailById(Long id) {
        chargesOwedDetailDao.deleteChargesOwedDetailById(id);
    }

    @Override
    public List<ChargesOwedDetail> getChargesOwedDetailListPage(ChargesOwedDetail chargesOwedDetail) {
        return chargesOwedDetailDao.getChargesOwedDetailListPage(chargesOwedDetail);
    }

    @Override
    public Integer getChargesOwedDetailListPageCount(ChargesOwedDetail chargesOwedDetail) {
        return chargesOwedDetailDao.getChargesOwedDetailListPageCount(chargesOwedDetail);
    }

    @Override
    public ChargesOwedDetail getChargesOwedDetailById(Long id) {
        return chargesOwedDetailDao.getChargesOwedDetailById(id);
    }


    @Override
    public List<ChargesOwedDetail> getChargesOwedDetailByCondition(Map<String, Object> map) {
        return chargesOwedDetailDao.getChargesOwedDetailByCondition(map);
    }


    @Override
    public void updateReduction(ChargesOwedDetail chargesOwedDetail) {
        ChargesOwed chargesOwed = chargesOwedDao.getChargesOwedById(chargesOwedDetail.getOwedId());
        Double frontMoney = chargesOwedDetail.getMoney();
        Double sourceMoney = chargesOwed.getMoney();
        Double descMoney = sourceMoney + frontMoney;
        chargesOwed.setMoney(descMoney);
        chargesOwedDao.updateChargesOwed(chargesOwed);
        chargesOwedDetail.setMoney(frontMoney);
        chargesOwedDetail.setClassId(chargesOwed.getClassId());
        chargesOwedDetail.setChargesType(2);
        chargesOwedDetail.setOwedId(chargesOwed.getId());
        chargesOwedDetail.setStuId(chargesOwed.getStuId());
        chargesOwedDetailDao.saveChargesOwedDetail(chargesOwedDetail);
    }


    @Override
    public List<PaymentProject> getProjectListByStuId(Map<String, Object> param) {
        return chargesOwedDetailDao.getProjectListByStuId(param);
    }
}
